<script setup>
import { getHotGoodsAPI } from '@/apis/detail';
import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';

// 适配title和数据
const props = defineProps({
  hotType: {
    type: Number,
    default: 1,
  }
})
// 适配 title 1：24小时榜单 2：周日榜单
const TYPEMAP = {
  1: '24小时榜单',
  2: '周日榜单',
}
const title = computed(() => {
  return TYPEMAP[props.hotType] || TYPEMAP['1']
})

// 获取数据
const hotList = ref({})
const getHostList = async (params) => {
  const res = await getHotGoodsAPI(params);
  hotList.value = res.result
}

// 获取路由
const route = useRoute()
// query 参数
const hotRequest = {
  id: route.params.id,
  type: props.hotType,
}
onMounted(() => {
  getHostList(hotRequest)
})
</script>

<template>
<div class="goods-hot">
  <h3>{{ title }}</h3>
  <!-- 商品区块 -->
  <RouterLink :to="`/detail/${item.id}`" class="goods-item" v-for="item in hotList" :key="item.id">
    <img :src="item.picture" alt="" />
    <p class="name ellipsis">{{ item.name }}</p>
    <p class="desc ellipsis">{{ item.desc }}</p>
    <p class="price">&yen;{{ item.price }}</p>
  </RouterLink>
  </div>
</template>

<style scoped lang="scss">
  .goods-hot {
    margin-bottom: 20px;
    h3 {
      height: 70px;
      background: $helpColor;
      color: #fff;
      font-size: 18px;
      line-height: 70px;
      padding-left: 25px;
      margin-bottom: 10px;
      font-weight: normal;
    }

    .goods-item {
      display: block;
      padding: 20px 30px;
      text-align: center;
      background: #fff;
      width: 280px;

      img {
        width: 160px;
        height: 160px;
      }

      p {
        padding-top: 10px;
      }

      .name {
        font-size: 16px;
      }

      .desc {
        color: #999;
        height: 29px;
      }

      .price {
        color: $priceColor;
        font-size: 20px;
      }
    }
  }
</style>
